var app = getApp();
Page({

  data: {
    lock:0,
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    info:[],
    suoding:'个人工单',
    date: '',
    liyou:'',
    date2:'',
    choose:'',
    itemList: ['正常', '返工','报废'],
    status:'点击选择状态',
    userInfo: null,
    title:'',
    buttom:'',
    zhicheng:'',
    
  },

  

  onLoad: function (options) {
    var that = this

    /**
     * 获取当前设备的宽高
     */
    wx.getSystemInfo( {

        success: function( res ) {
            that.setData( {
                winWidth: res.windowWidth,
                winHeight: res.windowHeight
            });
        }

    });

    var date = new Date();

    var jintian = date.getDate()
    var mingtian = date.getDate()+1

    var todate = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (jintian < 10 ? ("0" + jintian) : jintian);
    var todate2 = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (mingtian < 10 ? ("0" + mingtian) : mingtian);
    
    that.setData({ date: todate});
    that.setData({ date2: todate2});
  },
  onShow:function(){
    this.getlist()
  },

  qiehuan: function(e) {
    var that = this
    wx.showActionSheet({
      itemList: ['个人工单', '全部工单'],
      success(res) {

        // console.log(res.tapIndex)1
        if(res.tapIndex == 0)
          {
            this.setData({
              suoding: '个人工单'
      })
        }


        if(res.tapIndex == 1){
          this.setData({
            suoding: '全部工单'
    })
        }
        that.getlist()

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },

  swichNav: function( e ) {
    var that = this;
    if( this.data.currentTab === e.target.dataset.current ) {
        return false;
    } else {
        that.setData( {
            currentTab: e.target.dataset.current
        })
    }

    that.setData( { lock: e.target.dataset.current });
    that.getlist()
},

bindChange: function( e ) {

    var that = this;
    that.setData( { currentTab: e.detail.current });

},


  godetail: function(e) {
 
        wx.navigateTo({
          url: '/page/my/gongdandetail?id='+e.currentTarget.dataset.fee,
        });
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })

    this.getlist()
  },
  bindDateChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date2: e.detail.value
    })
    this.getlist()
  },

  getlist:function (){
    // var lid = 1
  
    var that = this
 
    wx.request({
      url: app.apiUrl + '/api/data/worksheet',
      data: {
        openid:wx.getStorageSync('openid'),
        groupid:wx.getStorageSync('groupid'),
        lock:that.data.lock,
        sdate:that.data.date,
        edate:that.data.date2,
      },
      method: 'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        if(res.data.code == 1){
          that.setData({ info: res.data.data});
            
        }else{
          wx.showModal({
            title: '温馨提示',
               content: res.data.msg,
                 showCancel: false
            });

            that.setData({ info: ''});
        }
     
      }
    });
  },
  
})